<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2024/8/8
 * Time: 10:34
 */
namespace app\api\controller\v2;
use think\log;
use think\facade\Db;
use app\Request;
use app\services\pay\WxpayServices;
use app\services\car\AlipayServices as alipay;
use app\services\pay\SmfpayServices;

class ThreeinonePayController
{

    public function __construct(Request $request,alipay $services)
    {
        $this->request = $request;
        $this->services = $services;
    }
    /*
     * 支付宝/微信/扫码富
     * 聚合支付
     *
     * */
        public function polymerization_Pay(Request $request){
            $data = $request->postMore([
                ['appid','2'],//1是正式2是测试3是AI约你游4是测试AI约你游
                ['vendorid','1'],//商户id
                ['order_type',''],//订单类型 1直营商户 2入驻商户
                ['pay_type',''],//支付类型 app/jsapi
                ['openid',''],//pay_type等于jsapi必传
                ['orderon',''],//订单号
                ['amount',''],//金额
                ['body',''],//订单详情
                ['quantity','1'],//商品数量
                ['price',''],//商品单价 支付宝用
                ['pay_client_type'],//wxpay,alipay,smfpay 支付平台
            ]);
            if(!$data) return app('json')->fail('参数错误');
            if(!$data['pay_client_type']) return app('json')->fail('pay_client_type不能为空');
            if($data['amount']<=0) return app('json')->fail('订单金额不能等于0！');
            switch (urldecode($data['pay_client_type'])) {
                case 'wxpay':
                    $pay = new WxpayServices();
                    $code = $pay->WeChatpay($data);
                    return app('json')->success("请求成功",$code);
                case 'alipay':
                    $pay = $this->services->Alipay($data);
                    $code['alipay_sdk'] = $pay;
                    return app('json')->success("请求成功",$code);
                case 'smfpay':
                    $log = new LogController();
                    $log_id = $log->add_log($data);
                    $pay = new SmfpayServices();
                    $code = $pay->smfpay($data);
                    $log = new LogController();
                    $log_id = $log->add_log($code,$log_id);
                    return app('json')->success("请求成功",$code);
                default:
            }
        }
}